<?php
class Mysql {
	
	private $host = "localhost";     
	private $user = "root";          
	private $password = "9d87s6";
	private $dbname = "files_catalog";
    
	private $mysqli = null;      
	private $active = false;
	
	private $error = null;
 
 	public function __contruct() {
 		$this->mysqli = new mysqli();
 	}
 
	public function connect() {
		if(!$this->active) {
			$this->mysqli = new mysqli($this->host, $this->user, $this->password, $this->dbname);
			
			if (mysqli_connect_errno()) {
				$this->active = false;
				$this->error = mysqli_connect_error();
				
				return false;
			}
			else {
				$this->active = true;
				return true;
			}
		} else {
			return true;
		}
	}
	
	public function disconnect() {
		if($this->active) {
			if($this->mysqli->close()) {
				$this->active = false; 
				return true; 
			} else {
				return false; 
			}
		}	
	}
	
	public function query($query) {
		$result = null;
		
		if($this->active) {
			$result = $this->mysqli->query($query);		
		}
		
		return $result;
	}
}

?>